﻿#pragma once
#include <assert.h>

class MemoryStatistics
{
public:
	enum
	{
		DEFAULT_SIZE = 1024 * 1024 * 10,
	};

	~MemoryStatistics()
	{
		assert(this->use_size_ == 0);
	}

	static MemoryStatistics* instance()
	{
		if (!mem_)
		{
			mem_ = new MemoryStatistics();
			mem_->total_size_ = DEFAULT_SIZE;
			mem_->use_size_ = 0;
		}
		return mem_;
	}

	static void destory()
	{
		if (mem_)
		{
			delete mem_;
			mem_ = nullptr;
		}
	}

	static void AddMemory(int size)
	{
		use_size_ += size;
	}
	
	static void RecyMemory(int size)
	{
		use_size_ -= size;
	}


private:
	MemoryStatistics() {};
	static int total_size_;
	static int use_size_;
	static MemoryStatistics *mem_;
};

MemoryStatistics *MemoryStatistics::mem_ = nullptr;
int MemoryStatistics::total_size_ = 0;
int MemoryStatistics::use_size_ = 0;
